<template>
  <div>
    <teleport to="body">
      <!-- 蒙版区域 -->
      <transition name="fade">
        <div
          v-if="modelValue"
          class="w-screen h-screen fixed z-40 bg-cyan-950/80 top-0 left-0"
          @click="emits('update:modelValue', false)"
        ></div>
      </transition>
      <!-- 内容区域 -->
      <transition name="content">
        <div
          v-if="modelValue"
          class="w-screen bg-white rou fixed z-50 bottom-0 dark:bg-zinc-800"
        >
          <slot></slot>
        </div>
      </transition>
    </teleport>
  </div>
</template>

<script setup>
import { watch } from 'vue'
import { useScrollLock } from '@vueuse/core'

const props = defineProps({
  categoryData: {
    type: Array,
    require: true
  },
  modelValue: {
    type: Boolean,
    require: true
  }
})
const emits = defineEmits(['update:modelValue'])

// ------ 滚动锁定 ------
const isLocked = useScrollLock(document.body)
watch(
  () => {
    console.log('拿到数据了', props.modelValue)
    return props.modelValue
  },
  (val) => {
    isLocked.value = val
  },
  {
    immediate: true
  }
)
</script>

<style lang="scss" scoped>
// fade 展示动画
.fade-enter-active {
  transition: all 0.3s;
}

.fade-leave-active {
  transition: all 0.3s;
}
// 准备进入之前，离开的时候
.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

// popup-down-up 展示动画
.content-enter-active {
  transition: all 0.3s;
}

.content-leave-active {
  transition: all 0.3s;
}

.content-enter-from,
.content-leave-to {
  transform: translateY(100%);
}
</style>
